<!DOCTYPE html>
<html>
{include file="public/head"}

<body style="margin-top: 0px;">
    <!-- 分割线 -->
    <div class="layui-container fly-marginTop">
        <div class="fly-panel fly-panel-user" pad20="">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <!-- <li><a href="UserLogin.html">登入</a></li> -->
                    <li class="layui-this">忘记密码</li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                    <div class="layui-tab-item layui-show">
                        <div class="layui-form layui-form-pane">
                            <form method="post" id="myform" action="{:url('user/toupdate')}">
                                <div class="layui-form-item">
                                    <label for="L_email" class="layui-form-label">邮箱</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="email" name="email" required="" lay-verify="email" autocomplete="off" class="layui-input">
                                    </div>
                                    <div id='errorMsg' class="layui-form-mid layui-word-aux">将用来找回密码</div>
                                </div>
                                <div class="layui-form-item">
                                    <label for="L_email" class="layui-form-label">验证码</label>
                                    <div class="layui-input-inline">
                                        <input type="text" id="verify" name="verify" required="" class="layui-input">
                                    </div>
                                    <div><img id="verify_img" src="{:url('web/User/ToPicture')}" alt="验证码" style="cursor:pointer" onclick="refreshVerify()"></div>
                                </div>
                                <button class="layui-btn" lay-filter="forget" lay-submit>提交</button>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
    <!-- 分割线 -->
</body>
<script>
function refreshVerify() {
    var ts = Date.parse(new Date()) / 1000;
    var img = document.getElementById('verify_img');
    img.src = "{:url('web/User/ToPicture')}";
}
layui.use(['form', 'jquery'], function() {
    var form = layui.form;
    var $ = layui.jquery;
    form.on('submit(forget)', function(data) {
        var var_email = $("#email").val();
        var var_verify = $("#verify").val();
        $.ajax({
            url: "{:url('user/judgeemail')}",
            data: { "email": var_email, "verify": var_verify, "type": "forget" },
            type: 'post',
            dataType: 'JSON',
            success: function(res) {
                // console.log("result="+res.result);
                if (res.result == -1) {
                    layer.msg('验证码输入错误');
                    refreshVerify();
                } else if (res.result == 0) { //不存在这个邮箱
                    layer.msg('此邮箱尚未注册！');
                    refreshVerify();
                } else if (res.result == 1) { //存在这个邮箱
                    layer.msg('发送成功');
                    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    // setTimeout("parent.location.reload()",1000);
                    parent.location.reload();
                    parent.location.href = "{:url('web/user/toupdate')}" + "?email=" + data.field['email'];
                }
            },
            error: function() {
                layer.msg('进入后台失败');
            }
        });
        return false;
    });
});
</script>

</html>